home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / user / reformat_schedule.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  5KB  |  176 lines

  1. /* Mode=Run */
  2. /* ***********************************************************************
  3.  
  4.     Reformat_Schedule.rexx v1.1 (03-7-99) for THE FOOTBALL REXX SUITE
  5.     -----------------------------------------------------------
  6.      by Mark Naughton
  7.      update by Heiko Schroeder (age@thepentagon.com)
  8.  
  9.     -This script formats a schedule file from DDMM to DDMMYYYY.
  10.  
  11.     -To use Reformat_Schedule.rexx you have to create a schedule file
  12.      with dates in DDMM.
  13.  
  14.     -The first line is to write
  15.      *DATES=DDMMYYYY
  16.      It means the first date of a game at season. E.g. *DATES=07081999
  17.  
  18.  
  19.      Version    Date     History
  20.     --------------------------------------------------------------------------
  21.       1.0       270599   First release.
  22.       1.1       030799   Update by Heiko Schroeder
  23.                          Fixes problem by starting with program football
  24.                          Automatically parsing of startmnth and year1, year2
  25.                          Variable start month of a season (not only July (7))
  26.                          Checks if the file has been reformatted
  27.                 250899   Added error messages and title. Update by Mark.
  28.                 280899   Converted to use locale. Some error messages, before
  29.                          reading the locale, will still be in English.
  30.                 190999   Changed schedule directory.
  31.  
  32.  
  33. ************************************************************************** */
  34.  
  35. parse arg filen      /* only filen will be give by main program */
  36.  
  37.  
  38. if open(datafile,"Data/Football.locale",'r') then do
  39.    line = readln(datafile)
  40.    locdir = strip(line)
  41.    close(datafile)
  42. end
  43. else do
  44.    say
  45.    say "ERROR :    (ReformatSchedule)"
  46.    say
  47.    say "Cannot read 'Data/Football.locale' for the locale settings."
  48.    exit
  49. end
  50.  
  51. locdir = locdir"User/Reformat_Schedule.data"
  52.  
  53. if open(datafile,"ENV:FootballRXPath",'r') then do
  54.    line = readln(datafile)
  55.    rxdir = strip(line)
  56.    close(datafile)
  57. end
  58. else
  59.    rxdir = "SYS:Rexxc/"
  60.  
  61. if exists(locdir) > 0 then do
  62.   address command rxdir'rx 'locdir
  63.   VarCount = getclip('VarCount')
  64.   do i = 1 to VarCount
  65.     interpret getclip('var.'i)
  66.   end
  67. end
  68. else do
  69.    say
  70.    say "ERROR :    (ReformatSchedule)"
  71.    say
  72.    say "Cannot find '"locdir"' to read locale settings."
  73.    exit
  74. end
  75.  
  76. say
  77. say center(rs_three,78)
  78. say "-------------------------------------------------------------------------------"
  79. say
  80. say rs_four
  81. say
  82.  
  83. filen = strip(filen)
  84. okay=0
  85. exit=0
  86.  
  87. if exists("Data/Schedules/"filen".schd") = 0  then do
  88.    say
  89.    say rs_error
  90.    say
  91.    say rs_one"'Data/Schedules/"filen".schd'."
  92.    exit
  93. end
  94.  
  95. if open(datafile,"Data/Schedules/"filen".schd",'r') then do
  96.    if open(datafile2,"Data/Schedules/"filen".schd2",'w') then do
  97.       do while ~eof(datafile) & exit=0
  98.          line = readln(datafile)
  99.  
  100.          if line = '' then leave
  101.          if line ~= '' & pos('*',line) = 0 then do
  102.             counter = words(line)
  103.             do i=1 to counter
  104.                sdate = word(line,i)
  105.  
  106.                If length(sdate)>4 then do                /* check if it's correct file */
  107.                   say rs_txt1
  108.                   say
  109.                   say rs_txt2
  110.                   say rs_txt3
  111.                   exit=1; okay =0
  112.                   Leave
  113.                End
  114.  
  115.                mnth  = substr(sdate,3,2)
  116.                if mnth >= startmnth then                 /* changed */
  117.                   sdate = sdate||year1" "
  118.                else do
  119.                   if mnth < startmnth & mnth ~= 0 then   /* changed */
  120.                      sdate = sdate||year2" "
  121.                   else
  122.                      sdate = sdate||"0000 "
  123.                end
  124.                writech(datafile2,sdate)
  125.             end
  126.             writeln(datafile2,"")
  127.          end
  128.          else
  129.             if length(line) = 15 & pos('*DATES=',line) > 0 then do
  130.                /* parsing of startmonth, year1, year2 */
  131.                startmnth = strip(substr(line,10,2),'L',0)
  132.                year1 = substr(line,12,4)
  133.                year2 = year1 + 1
  134.                writeln(datafile2,line)
  135.                okay=1
  136.             end
  137.             else do
  138.                /* no parsing of startmonth, year1, year2 possible */
  139.                say rs_error
  140.                say
  141.                say rs_txt4"'"filen".schd'"rs_txt5
  142.                say rs_txt6
  143.                say
  144.                leave
  145.             end
  146.       end
  147.       close(datafile2)
  148.    end
  149.    else do
  150.       close(datafile)
  151.       say
  152.       say rs_error
  153.       say
  154.       say rs_two"'Data/Schedules/"filen".schd2'"rs_txt7
  155.       exit
  156.    end
  157.    close(datafile)
  158. end
  159. else do
  160.    say
  161.    say rs_error
  162.    say
  163.    say rs_two"'Data/Schedules/"filen".schd'"rs_txt8
  164.    exit
  165. end
  166.  
  167.  
  168. /* only if reformatting was successful the message will be appear */
  169.  
  170. If okay=1 then do
  171.    say rs_txt1
  172.    say
  173.    say rs_txt9"'"filen".schd2'."
  174. end
  175. exit
  176.